def get_input(prompt):
    while True:
        user_input = input(prompt).strip()
        if user_input:  # 确保输入不为空
            return user_input
        print("输入不能为空，请重新输入。")


def get_amount():
    while True:
        try:
            return float(get_input("请输入金额: "))
        except ValueError:
            print("请输入一个有效的数字。")


def get_currency():
    while True:
        currency = get_input("请输入货币类型（人民币: 'cny', 美元: 'usd'): ").lower()
        if currency in ['cny', 'usd']:
            return currency
        print("货币类型无效，请重新输入。")


def convert_currency(amount, currency, exchange_rate=7.0):
    if currency == 'usd':
        return amount * exchange_rate
    elif currency == 'cny':
        return amount / exchange_rate
    else:
        return None


def display_result(amount, converted_amount):
    print(f"转换后的金额是: {converted_amount:.2f}")


def main():
    exchange_rate = 7.0
    while True:
        amount = get_amount()
        currency = get_currency()
        converted_amount = convert_currency(amount, currency, exchange_rate)
        if converted_amount is not None:
            display_result(amount, converted_amount)
        else:
            print("货币类型转换出错，请重新输入。")

        continue_choice = get_input("是否继续（y/n）: ").strip().lower()
        if continue_choice == 'n':
            print("程序结束。")
            break


if __name__ == "__main__":
    main()